home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 7.0 KB | 185 lines |
- Screen Open 0,320,200,8,0 : Curs Off : Flash Off : Cls 0
- Palette 0,$F00,$F0,$F,$FFF
- Ink 0 : Bar 0,0 To 15,15
- Ink 1 : Bar 16,0 To 31,15
- Ink 2 : Bar 0,16 To 15,31
- Ink 3 : Bar 16,16 To 31,31
- Get Icon 1,0,0 To 32,32 : Make Icon Mask
- _MAKEMASK[0,2,5,6,0,0,32,32,1]
- Pen 4 : Paper 0
- Locate 0,10 : Print 'A 4-colour icon...'
- 'prove that it worked...
- Ink 4 : Bar 40,40 To 79,79
- Print '... a white block... (press a key)'
- Wait Key
- Paste Icon 44,44,1
- Print '... with the icon masked in colour 2!'
-
- Procedure _MAKEMASK[_SCREEN,_COLOUR,TEMP1,TEMP2,X1,Y1,X2,Y2,_ICON]
- '
- ' Version: 1.0
- ' By: ** Michael Sikorsky **
- ' (special thanks to ** Rich Helvey ** for the idea of using the
- ' buffer screen to stop my amiga from crashing becasue of my
- ' inexperience with dirrect blitter access.)
- ' e-mail: sikorsky@bode.ee.ualberta.ca
- '
- ' Distribution: This program is freely distributable. All I ask is if
- ' you make changes,improvements, or bug fixes (etc) that
- ' you mail me a new copy of the source. Also somekind
- ' of acknowledgment in your greetings/credits/manual/etc
- ' would be appreciated, thanks.
- '
- ' Requirements: none.
- '
- ' Description: Creates a Mask of any color for an Icon. It is done
- ' quickly at the expense of some memory needed for 2
- ' extra temp screens that are only 2 color screens. This
- ' procedure also is intended to also show how the logic of
- ' mask making can be accomplished. If direct use of the
- ' blitter was employed then the need for the 2 extra screens
- ' and the trouble with getting the mask data linear in
- ' memory would be eliminated.
- '
- ' Parameters: _SCREEN=number of the screen where image data is.
- ' _COLOUR=number of the colour you want Masked.
- ' TEMP1=number of first temporary screen.
- ' TEMP2=number of second temporary screen.
- ' (X1,Y1)=top left hand corner of image.
- ' (X2,Y2)=bottom right hand corner of image.
- ' _ICON=number of the Icon that you want the mask for.
- '
- ' notes: - TEMP1,TEMP2 screens are created (1 bitplane) so if these
- ' screens are defined elsewhere they will be deleted.
- ' - can be changed to work for Bob's easily. use Sprite Base()
- ' instead of Icon Base().
- ' - will work for any number of colors as long as there are
- ' no tricks like HAM going on... therefore it will mask out
- ' colors on a EHB screen but not on a HAM screen (well it will
- ' but it may/may not work properly.)
- '
- ' Returns: nothing.
- '
-
- '****** Make The Mask....
-
- _T_SCR=Screen
-
- WID=Screen Width : HIT=Screen Height
-
- Screen Open TEMP1,WID,HIT,2,Lowres : Screen Hide TEMP1 : Curs Off
- Screen Open TEMP2,WID,HIT,2,Lowres : Screen Hide TEMP2 : Curs Off
- Screen TEMP1 : SB1=Phybase(0)
- Screen TEMP2 : Cls 0
-
- BPLEN=WID*HIT/8.0
-
- Screen _SCREEN : _NUM_OF_PLANES=Deek(Screen Base+$50)
-
- _COL$=Flip$(Bin$(_COLOUR,_NUM_OF_PLANES)-"%")
-
- '
- ' the reasoning why I OR and NOT is this... I want the color that we are
- ' masking to contribute nothing to the mask.. ie. 0 or X=X... thats why
- ' I have to NOT the "1" values... this ends up making the color we want to
- ' not contribute to the mask.... mike
- '
- ' ie. if you had a 4 color screen then that takes 2 bitplane's and say
- ' you wanted to mask out Color 1 (%01) -->
- '
- ' bitplane 0: bitplane 1: Resultant Colors Mask Should Be:
- ' on screen:
- ' 0 1 0 0 0 1 1 0
- ' 0 1 1 1 2 3 1 1
- '
- ' therefore because Color 1 is represnted by %01 on the bitpalnes
- ' I want to do this --> (bitplane 1) OR (NOT(bitplane 0))=Mask
- '
- ' bitplane 1: NOT(bitplane0): Mask:
- '
- ' 0 0 OR 1 0 = 1 0 Correct.
- ' 1 1 1 0 1 1
- '
-
- For X=0 To _NUM_OF_PLANES-1
- Copy Phybase(X),Phybase(X)+BPLEN To SB1
- _VAL$=Mid$(_COL$,X+1,1)
- If _VAL$="1"
- ' Not
- Screen Copy TEMP1,0,0,WID,HIT To TEMP1,0,0,%110000
- End If
- 'or
- Screen Copy TEMP1,0,0,WID,HIT To TEMP2,0,0,%11100000
- Next
- ' uncomment this if you want the not of the mask.
- 'NOT -- if want opposite mask
- 'Screen Copy temp2,0,0,WID,HIT To temp2,0,0,%110000
-
- '****** Copy Mask into the Icon...
- ' Screen To Front TEMP1
- Screen TEMP1
- Cls 0 : Rem very important .. ie. so that extra data copied is just blank
- '
- ' copy the screen data to be used as the mask to (0,0)
- '
- Screen Copy TEMP2,X1,Y1,X2,Y2 To TEMP1,0,0
-
- ' Screen To Front TEMP2
- Screen TEMP2
- Cls 0 : Rem very important look at note below -->
-
- '
- ' ** amos Icons/Bobs are all on Word Boundarys... that is why
- ' you can't figure out the length of a line of an icon by just using
- ' (x2-x1)... so if you grabbed a icon of width 50 that takes
- ' at leats 4 words (4*16=64 --> 64-50=extra 14 pixels/line)
- ' that is why you need the cls 0 so that the extra room gets
- ' filled with a zero therefore masking out the data...
- '
- X_SIZE=Deek(Icon Base(_ICON)) : Rem x-size of icon in words
- LINE_LEN=(X_SIZE*16) : Rem size of one line in mask in pixels
- '
- ' have to be able to have an exact number of line_lengths across in
- ' the linear mask screen.. ie. if the lenght of one line of the mask
- ' is 48 then say _page_width=320 --> 320 mod 48=32 then linear mask
- ' screen width should be _page_width-32=320-32=288... need this because
- ' you are grabbling the mask linearly from memory so if there is blank
- ' space's they wreck the mask...
- '
- _T=WID mod LINE_LEN
- _LINEAR_MASK_WID=WID-_T
- Screen Open TEMP2,_LINEAR_MASK_WID,HIT,2,Lowres : Curs Off : Cls 0 : Screen Hide TEMP2
- 'Screen Show TEMP2
-
- '
- ' need to copy the screen data into the mask.. but amos screws up
- ' screens that are not at multiples of 16 in width so can't make a
- ' small screen then just copy the whole bitplane directly into
- ' the mask so this next bit just writes out screen data linearly
- ' across the screen so that it is possible to copy from the bitplane
- ' to get the mask data...
- '
- XP=0 : YP=0
- For X=1 To(Y2-Y1)
- Screen Copy TEMP1,0,X-1,0+LINE_LEN,X To TEMP2,XP,YP
- XP=XP+LINE_LEN
- If(XP/LINE_LEN) mod(_LINEAR_MASK_WID/LINE_LEN)=0 : Inc YP : XP=0 : End If
- Next
-
- _MASK_LENGTH=Leek(Icon Base(-_ICON))-4
- _MASK_ADDR=Icon Base(-_ICON)+4
-
- Copy Phybase(0),Phybase(0)+_MASK_LENGTH To _MASK_ADDR
-
- 'Print Hex$(Phybase(0)),X_SIZE,_MASK_LENGTH,Hex$(_MASK_ADDR)
- 'Wait Key
-
- Screen Close TEMP1
- Screen Close TEMP2
-
- Screen _T_SCR : Rem set the current screen back..
-
-
- '*********
- '
- End Proc